# 集合set，无序，没有重复元素，可以进行交集并集运算
s = set()
print(s, type(s))

s = {1, 2, 3, 4, 4}
print(s)

s = set([1, 2, 3])  # list -> set
print(s, type(s))

s = set((1, 2, 3))  # tuple -> set
print(s, type(s))

s = set("123")  # str -> set
print(s, type(s))

s = set({"name": "huang", "age": 18})  # dict -> set
print(s)

# 通用函数
# len()/min()/max()/del

# 集合的遍历
print("=" * 50)

# for i in s:
#     print(i)
#
# for index, value in enumerate(s):
#     print(index, value)


# 常用方法
s.remove("name")
print(s)

s.clear()
print(s)

s.update({1, 2, 3, 4, 5})
print(s)

s.add(6)
print(s)

s2 = {4, 5, 6, 7, 8}
# 交集
# print(s & s2)
print(s.intersection(s2))
# 并集
# print(s | s2)
print(s.union(s2))

# 列表去重
score = [80, 90, 87, 90, 60, 80]
s = set(score)
print(s)
# 统计各个分数有几个学生
d = dict()
for i in s:
    t = score.count(i)
    d[i] = t  # 保存下来
print(d)
for k, v in d.items():
    print("得分为%d的学生有%d个" % (k, v))
